﻿using System.Collections.Generic;

namespace AIFSCMSClient
{
    public class CriteriaBuilderResult<T> where T : IExpressionPredicate, new()
    {
        Queue<string> buffer;
        
        internal CriteriaBuilderResult(Queue<string> Buffer)
        {
            buffer = Buffer;
        }

        /// <summary>
        /// Gets the current expression array. Once you call this method the buffer is cleared and
        /// the builder is ready for new expression building
        /// </summary>
        public string[] CriteriaExpression
        {
            get
            {
                string[] buff = buffer.ToArray();

                buffer.Clear();

                return buff;
            }
        }

        /// <summary>
        /// Used internally to queue the criteria and operators
        /// </summary>
        internal Queue<string> CriteriaExpressionQueue
        {
            get
            {
                return buffer;
            }
        }

        public T AndStringCriteria(string CriteriaName)
        {
            ExpressionBuilder<T> builder = new ExpressionBuilder<T>(buffer);
            return builder.CreateStringCriteria(CriteriaName);
        }

        public T AndDateCriteria(string CriteriaName)
        {
            ExpressionBuilder<T> builder = new ExpressionBuilder<T>(buffer);
            return builder.CreateDateCriteria(CriteriaName);
        }

        public T AndBooleanCriteria(string CriteriaName)
        {
            ExpressionBuilder<T> builder = new ExpressionBuilder<T>(buffer);
            return builder.CreateBooleanCriteria(CriteriaName);
        }

        public T AndNumericCriteria(string CriteriaName)
        {
            ExpressionBuilder<T> builder = new ExpressionBuilder<T>(buffer);
            return builder.CreateNumericCriteria(CriteriaName);
        }
    }
}
